<?php
/**登录控制器
 * @Author: 976123967@qq.com
 * @Date:   2014-09-07 23:46:26
 * @Last Modified by:   chen
 * @Last Modified time: 2014-09-08 22:11:22
 */
class LoginControl extends CommonControl{

	/**
	 * [index 登录]
	 * @return [type] [description]
	 */
	public function index()
	{
		if(IS_POST)
		{
			$model = K('User');
			if(!$user = $model->check_login())
				$this->error($model->error);
			$auto = Q('post.auto',null,'intval');
			session('uid',$user['uid']);
			session('uname',$user['uname']);
			if($auto)
			{
				setcookie(session_name(),session_id(),time()+60*60*24*7,'/');
			}
			else
			{
				setcookie(session_name(),session_id(),0,'/');
			}
			$this->success('登录成功',U('Index/Index/index'));
		}
		$this->display();
	}

	/**
	 * [out 退出]
	 * @return [type] [description]
	 */
	public function out()
	{
		session(null);
		setcookie(session_name(),session_id(),-1,'/');
		$this->success('退出成功',U('Index/Index/index'));
	}
}